# 文件对象的常用方法
filePath = 'D:\\hxy\\uploadPath\\abc.txt'

print('------------------读read()函数-----------------')
'''read(index) 可以填写读取元素个数索引'''
file1 = open(filePath, 'r', encoding='utf-8')
print('read()读取文件内容：', file1.read()) #read() 返回类型<class 'str'>
file1.close()

print('------------------读readline()函数-----------------')
file2 = open(filePath, 'r', encoding='utf-8')
print('readline()读取文件一行内容：', file2.readline())  #readline() 返回类型<class 'str'>
file2.close()

print('------------------读readlines()函数-----------------')
file3 = open(filePath, 'r', encoding='UTF-8')
print('readlines()读取文件每一行的数据：', file3.readlines()) #readlines() 返回类型<class 'list'>
file3.close()

print('------------------写write()函数-----------------')
# 注意： 写入时 格式不对 要将encoding='UTF-8' 加上
file4 = open('D:\\hxy\\uploadPath\\bbb.txt', 'a')
lst = ['Python', 'Hello', 'World!']
file4.write('abc')
# file4.writelines(lst) #将writelines() 将列表数据拼接为一块写入文件；
print('tell() 返回文件指针的当前位置：', file4.tell()) #结果4
file4.close()

